package com.teachoa.interceptor;

import java.util.List;
import java.util.Map;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;
import com.teachoa.util.Lists;

@SuppressWarnings("rawtypes")
public class LoginInterceptor implements Interceptor {
	
	static List exceptUrls = Lists.newArrayList("/", "/login");

	@Override
	public void intercept(ActionInvocation ai) {
		String uri = ai.getController().getRequest().getRequestURI();
		Controller c = ai.getController();
		Map userMap = c.getSessionAttr("currentUser");
		if(userMap==null&&!exceptUrls.contains(uri)) {
			System.err.println("非法跳转");
			c.redirect("/");
		} else {
			System.err.println("继续执行");
			ai.invoke();
		}
	}

}
